package com.eschool.controller;

import com.eschool.pojo.*;
import com.eschool.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Configuration
public class CourseController {
    @Autowired
    CourseService courseService;


    @RequestMapping("/course/chooseCourse")
    public ServerResult chooseCourse(ChooseCourseDTO chooseCourseDTO) {
        int updateRow = courseService.ChooseCourse(chooseCourseDTO);
        if (updateRow == -1) {
            return new ServerResult(500, "grade wrong", null);
        } else if (updateRow == 0) {
            return new ServerResult(200, "fail", null);
        } else {
            return new ServerResult(0, "success", null);
        }
    }


    @RequestMapping("/course/getScoreByInfo")
    public ServerResult getScoreByInfo(ScoreDTO scoreDTO) {
        List<ScoreDAO> scoreList = courseService.getScoreByInfo(scoreDTO);
        return new ServerResult(0, "success", scoreList);
    }

    @RequestMapping("/courses/getCourses")
    public ServerResult getCourses(@RequestParam String studentId,
                                   @RequestParam(required = false) String grade) {
        List<CourseVO> courses = courseService.getCourses(studentId, grade);
        return new ServerResult(0, "success", courses);

    }

    @RequestMapping("/course/getConflictCourse")
    public ServerResult getConflictCourse(String studentId){
        List<CourseDAO> courseDAOS = courseService.getConflictCourse(studentId);
        return new ServerResult(0,"success",courseDAOS);
    }

    @RequestMapping("/course/getCourseByGrade")
    public ServerResult getCourseByGrade(String studentId,String academicYear, String semester){
        return new ServerResult(0,"success",courseService.getCourseByGrade(studentId,academicYear,semester));
    }

    @RequestMapping("/course/getGradeConflictCourses")
    public ServerResult getGradeConflictCourses(String studentId, String academicYear, String semester){
        return new ServerResult(0,"success",courseService.getGradeConflictCourses(studentId,academicYear,semester));
    }

    @RequestMapping("/course/getGradeRightCourses")
    public ServerResult getGradeRightCourses(String studentId, String academicYear, String semester){
        return new ServerResult(0,"success",courseService.getGradeRightCourses(studentId,academicYear,semester));
    }

    @RequestMapping("/course/getChosenCourse")
    public ServerResult getChosenCourse(String studentId){
        return new ServerResult(0,"success",courseService.getChosenCourse(studentId));
    }

    @RequestMapping("/course/deleteCourse")
    public ServerResult deleteCourse(String studentId,String courseid){
        int updateRow = courseService.DeleteCourse(studentId,courseid);
        if(updateRow==0){
            return new ServerResult(200,"fail",null);
        }
        else if(updateRow==1){
            return new ServerResult(0,"success",null);
        }
        else{
            return new ServerResult(50,"请到控制台查看错误",null);
        }
    }
}
